// 将字符串字面量类型按照指定字符分割为元组，无法分割则返回原字符串字面量
type SplitString<
  // 要处理的字符串
  T extends string,
  // 分隔符
  S extends string,
  // 要返回的数组
  F extends any[] = []
  // '' - 'flag'   根据infer来左右分割，左边放到数组中，右边递归，最终在结果集中增加无法匹配的即可
> = T extends `${infer L}${S}${infer R}`
  ? SplitString<R, S, [...F, L]>
  : [...F, T];

type A1 = SplitString<"handle-open-flag", "-">; // ["handle", "open", "flag"]
type A2 = SplitString<"oepn-flag", "-">; // ["open", "flag"]
type A3 = SplitString<"handle.open.flag", ".">; // ["handle", "open", "flag"]
type A4 = SplitString<"open.flag", ".">; // ["open", "flag"]
type A5 = SplitString<"open.flag", "-">; // ["open.flag"]
export {};
